package com.gsdxsys.dao.impl;

import java.sql.Connection;
//import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.gsdxsys.dao.ADminiDao;
import com.gsdxsys.entity.Admin;

public class AdminDaoImpl extends BaseDao implements ADminiDao{  

	public int insertAdmin(Admin admin) {
		int result=0;
		String sql="insert into admini (username,password,realname) value (?,?,?)";
		Object[] values= {admin.getUsername(),admin.getPassword(),admin.getRealname()};
		Connection conn=DbUtils.createConn();
		result=super.executeUpdate(conn, sql, values);
		return result;

	}

	public Admin selectByUsername(String username) {
		Admin admin=null;
			String sql="select * from admini where username=?";
			Object[] values= {username};
			Connection conn=DbUtils.createConn();
			ResultSet rs=super.executeQuery(conn, sql, values);
			try{
				if(rs.next())
					{
					admin=new Admin();
					admin.setAdminid(rs.getInt("adminiID"));
					admin.setPassword(rs.getString("password"));
					admin.setUsername(rs.getString("username"));
					admin.setRealname(rs.getString("realname"));
					return admin;
					}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return admin;
	}

	public int delById(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int updateAdmin(Admin admin) {
		// TODO Auto-generated method stub
		return 0;
	}


}
